package com.jianying.mapper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.jianying.base.BaseMapper;
import com.jianying.dataSource.TargetDataSource;
import com.jianying.domain.Product;

@Repository("productMapper")
public class ProductMapper extends BaseMapper {
	
	private final static String NAME_SPACE = "com.jianying.mapper.ProductMapper.";

	@TargetDataSource(name="ds1")
	public void insert(Product entity) {
		getSqlSessionTemplate().insert(NAME_SPACE + "insert", entity);
	}
	
	public List<Product> all(Integer tenantId) {
		return getSqlSessionTemplate().selectList(NAME_SPACE + "all", tenantId);
	}
	
	@TargetDataSource(name="ds1")
	public Product findByProductNo(String productNo, Integer tenantId){
		Map<String, Object> map = new HashMap<>();
		map.put("productNo", productNo);
		map.put("tenantId", tenantId);
		return getSqlSessionTemplate().selectOne(NAME_SPACE + "findByProductNo", map);
	}
	
	public Product find(Integer id){
		return getSqlSessionTemplate().selectOne(NAME_SPACE + "find", id);
	}

}
